import { ProColumns } from '@ant-design/pro-table'
import { Tag } from 'antd'

const devEnum: Record<string, any> = {
    开发环境: { color: 'green', text: '开发环境' },
    预发环境: { color: 'volcano', text: '预发环境' },
    生产环境: { color: 'red', text: '生产环境' },
}

export const repoColumns: ProColumns<IT.IVersionRepo>[] = [
    { title: '#', dataIndex: 'index', valueType: 'index', width: 30 },
    { title: '编号', dataIndex: 'repoid', hideInSearch: true, width: 50, ellipsis: true, editable: false },
    { title: '名称', dataIndex: 'repoName', width: 80, ellipsis: true },
    { title: '仓库', dataIndex: 'repoPath', width: 150, ellipsis: true },
    { title: '仓库名', dataIndex: 'repoRepo', width: 80, ellipsis: true, editable: false },
    { title: '创建人', dataIndex: 'au', hideInSearch: true, width: 60, ellipsis: true, editable: false },
    { title: '创建时间', dataIndex: 'ct', hideInSearch: true, width: 60, ellipsis: true, editable: false },
    { title: '更新人', dataIndex: 'ed', hideInSearch: true, width: 60, ellipsis: true, editable: false },
    { title: '更新时间', dataIndex: 'ut', hideInSearch: true, width: 60, ellipsis: true, editable: false },
    {
        title: '操作',
        key: 'option',
        width: 100,
        valueType: 'option',
        render: (_, row, index, action) => [
            <a
                key='a'
                onClick={() => {
                    action.startEditable(row.repoid as string)
                }}>
                编辑
            </a>,
        ],
    },
]

export const branchColumns: ProColumns<IT.IVersionBranch>[] = [
    { title: '#', dataIndex: 'index', valueType: 'index', width: 30 },
    { title: '编号', dataIndex: 'branchid', hideInSearch: true, width: 50, ellipsis: true, editable: false },
    { title: '分支', dataIndex: 'branch', width: 80, ellipsis: true },
    {
        title: '环境',
        dataIndex: 'branchCur',
        valueType: 'select',
        valueEnum: devEnum,
        order: 9,
        render: (_, record) => <Tag color={devEnum[record.branchCur as string].color}>{record.branchCur}</Tag>,
        width: 150,
        ellipsis: true,
    },
    {
        title: '所属客户',
        dataIndex: 'company',
        renderText: (_, r) => r.company?.companyName,
        order: 10,
        width: 80,
        ellipsis: true,
        editable: false,
    },
    { title: '创建人', dataIndex: 'au', hideInSearch: true, width: 60, ellipsis: true, editable: false },
    { title: '创建时间', dataIndex: 'ct', hideInSearch: true, width: 60, ellipsis: true, editable: false },
    { title: '更新人', dataIndex: 'ed', hideInSearch: true, width: 60, ellipsis: true, editable: false },
    { title: '更新时间', dataIndex: 'ut', hideInSearch: true, width: 60, ellipsis: true, editable: false },
    {
        title: '操作',
        key: 'option',
        width: 100,
        valueType: 'option',
        render: (_, row, index, action) => [
            <a
                key='a'
                onClick={() => {
                    action.startEditable(row.branchid as string)
                }}>
                编辑
            </a>,
        ],
    },
]

export const flowColumns: ProColumns<IT.IVersion>[] = [
    { title: '#', dataIndex: 'index', valueType: 'index', width: 30 },
    { title: '编号', dataIndex: 'versionid', hideInSearch: true, width: 50, ellipsis: true },
    {
        title: '环境',
        dataIndex: 'branch',
        valueType: 'select',
        valueEnum: devEnum,
        order: 9,
        render: (_, record) => (
            <Tag color={devEnum[record.branch?.branchCur as string].color}>{record.branch?.branchCur}</Tag>
        ),
        width: 60,
        ellipsis: true,
    },
    {
        title: '项目',
        dataIndex: 'project',
        render: (_, record) => record.project?.projectName,
        width: 100,
        ellipsis: true,
    },
    {
        title: '客户',
        dataIndex: 'company',
        render: (_, record) => record.company?.companyName,
        width: 100,
        ellipsis: true,
    },
    {
        title: '版本',
        dataIndex: 'version',
        render: (_, record) => `v${record.version}`,
        hideInSearch: true,
        width: 60,
        ellipsis: true,
    },
    { title: '更新服务数', dataIndex: 'updataCount', hideInSearch: true, width: 50, ellipsis: true },
    {
        title: '更新信息',
        dataIndex: 'context',
        renderText: (_, record) => record.context || '尚未填写',
        width: 120,
        ellipsis: true,
    },
    { title: '版本日期', dataIndex: 'ct', valueType: 'date', hideInSearch: true, width: 80, ellipsis: true },
    { title: '更新人', dataIndex: 'ed', hideInSearch: true, width: 60, ellipsis: true },
    { title: '更新时间', dataIndex: 'ut', hideInSearch: true, width: 60, ellipsis: true },
]
